package org.spark.example

import org.apache.spark.{SparkConf, SparkContext}

/**
  * @Author: chengjj
  * @Date: 2020-08-24
  */
object JoinTest {
    def main(args: Array[String]): Unit = {
        val conf = new SparkConf();
        conf.setAppName("test").setMaster("local");
        val sc = new SparkContext(conf);
        val a = sc.makeRDD(List(("a", "a"), ("b", "b"), ("c", "c1"), ("c", "c2")));
        val b = sc.makeRDD(List(("a", 1), ("b", 2), ("d", 4)));

        val c = a.join(b, 1);
        println("inner join")
        c.foreach(x => println(x));

        println("left join")
        val l = a.leftOuterJoin(b, 1);
        l.foreach(x => println(x))

        println("right join")
        val r = a.rightOuterJoin(b, 1);
        r.foreach(x=>println(x));
    }
}
